package com.xr.wage.commonTools;

import java.sql.*;

import com.bstek.dorado.common.*;
import com.bstek.dorado.common.ds.JdbcDataSourceConfig;
import com.bstek.dorado.data.*;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;

/**
 * bonusQueryViewModel
 */
public class bonusQueryViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters, ParameterSet outParameters)
      throws Exception {
	  JdbcDataSourceConfig dsc =new JdbcDataSourceConfig();
	   dsc.setName("TEMPUSER");

	  dsc.setDriver("oracle.jdbc.driver.OracleDriver");
	  dsc.setUrl("jdbc:oracle:thin:@117.135.144.101:1521:bsgdb");
	  dsc.setUser("TEMPUSER");
	  dsc.setPassword("TEMPUSER");
/*		HttpDoradoContext ht = (HttpDoradoContext) DoradoContext.getContext();
		HttpServletRequest req = ht.getRequest();*/
	  Dataset ds =getDataset("dataset1");
		Connection connection = dsc.getPool().getConnection();
		Statement st=null;
		ResultSet rs=null;
		CallableStatement cs =null;
		String id="";
		try{
	 
			st = connection.createStatement();
			rs=st.executeQuery("select seq_jj_plan.nextval from dual");
			rs.next();
			id=rs.getString(1);
			st.execute("insert into jj_plan(jj_plan_id, bonus, send_month_wage )values("+id+","+ds.getDouble("BONUS")+","+ds.getDouble("SEND_MONTH_WAGE")+")");
			
			cs =connection.prepareCall("{call sys.pck_jj.hlbsBonus(?)}");
			  
			cs.setString(1, id);
			cs.execute();      
			
			outParameters.setValue("id", id);
		} finally{
			 cs.close();
			rs.close();
			st.close();
			connection.close();
		}	


  }

}
